import { createApp } from 'vue'
import App from './App.vue'
import router from "@/router"
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createPinia } from 'pinia'
import '@/router/permission'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const pinia = createPinia()
const app = createApp(App)

//全局数据挂载
app.config.globalProperties.$img=process.env.VUE_APP_BASE_API+`/my/file/get/byId?fileId=`
app.config.globalProperties.$video=process.env.VUE_APP_BASE_API+`/my/file/video/`
app.config.globalProperties.$upFile=process.env.VUE_APP_BASE_API+`/my/file/upFile`

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

const debounce = (fn, delay) => {
    let timer
    return (...args) => {
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(() => {
            fn(...args)
        }, delay)
    }
}

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
    constructor(callback) {
        callback = debounce(callback, 200);
        super(callback);
    }
}

pinia.use(piniaPluginPersistedstate)
app.use(ElementPlus)
app.use(router)
app.use(pinia)
app.mount('#app')

